package com.aaa.pay.util;


import com.aaa.pay.dao.PayDao;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * fileName:expenditureLog
 * description:
 * author:lk
 * createTime:2020/3/20 9:51
 * version:1.0.0
 */
@Component
@Aspect
public class payLog {

    @Autowired
    private PayDao payDao;

    @Pointcut("execution(int com.aaa.pay.dao.PayDao.pay*(..))")
    public void pointA(){
    }

    /**
     * 用户消费后，将消费记录添加到消费记录表中
     * 后置通知
     */
    @AfterReturning( pointcut = "pointA()")
    public void  afterRetruningLog(JoinPoint joinPoint){
        //接待点类获取到连接点信息
        String methodName = joinPoint.getSignature().getName();
        Object[] args = joinPoint.getArgs();
        payDao.expenditureLog((Map) args[0]);
    }
}
